import React, { useState, useEffect } from "react";
import { useParams } from "react-router-dom";
import { getTextDetail } from "../../../components/api";
import Back from "../back";

interface IText {
  title?: string;
  id?: number;
  author?: string;
  [propName: string]: any;
}

export default function Detail() {
  let [textCon, setTextCon] = useState<IText>({});
  let { id } = useParams();
  // console.log(id)

  const getText_detail = async () => {
    let res = await getTextDetail(id);
    console.log(res, "text");
    setTextCon(res.data[0]);
  };

  useEffect(() => {
    getText_detail();
  }, []);

  return (
    <div style={{ padding: 10 }}>
      <Back></Back>
      <h2>{textCon.title}</h2>
      <p>作者：{textCon.author}</p>
      <p>{textCon.create_time}</p>
      <div style={{ marginTop: 20, fontSize: 14, lineHeight: "24px" }}>
        {textCon.content}
      </div>
    </div>
  );
}
